package org.ee.system.reository;

import org.ee.system.domain.UserInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

/**
 * 测试
 */
public interface UserRepository extends JpaRepository<UserInfo, Long> {

    /**
     *
     * @param userName
     * @return
     */
    Optional<UserInfo> findByUserName(String userName);

    @Query(value="select distinct u from UserInfo u left join fetch u.userRoles ur left join fetch ur.role",
    countQuery = "select count(u) from UserInfo u")
    Page<UserInfo> findAllWithRoles(Pageable pageable);
}
